package com.feisuanyz.lyweb01.controller;

import com.feisuanyz.lyweb01.constant.ResultCodeConstant;
import com.feisuanyz.lyweb01.pojo.domain.CooperativePurchaseDO;
import com.feisuanyz.lyweb01.pojo.dto.CooperativePurchaseDTO;
import com.feisuanyz.lyweb01.pojo.dto.CreateGroup;
import com.feisuanyz.lyweb01.pojo.dto.DeleteGroup;
import com.feisuanyz.lyweb01.pojo.dto.RestResult;
import com.feisuanyz.lyweb01.pojo.dto.UpdateGroup;
import com.feisuanyz.lyweb01.pojo.query.CooperativePurchaseQuery;
import com.feisuanyz.lyweb01.pojo.query.QueryGroup;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.CooperativePurchaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 合作购买
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Tag(name = "合作购买")
@RequestMapping("cooperative-purchase")
@RestController
public class CooperativePurchaseController {

    @Autowired
    private CooperativePurchaseService cooperativePurchaseService;

    /**
     * 获取合作购买信息列表
     *
     * @param query 合作购买查询对象
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @Operation(summary = "获取合作购买信息列表")
    public RestResult<PageResult<CooperativePurchaseDO>> getCooperativePurchaseList(@Validated(QueryGroup.class) CooperativePurchaseQuery query) {
        PageResult<CooperativePurchaseDO> result = cooperativePurchaseService.getCooperativePurchaseList(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 获取合作购买信息详情
     *
     * @param query 合作购买查询对象
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @Operation(summary = "获取合作购买信息详情")
    public RestResult<CooperativePurchaseDO> getCooperativePurchaseInfo(@Validated(QueryGroup.class) CooperativePurchaseQuery query) {
        CooperativePurchaseDO result = cooperativePurchaseService.getCooperativePurchaseInfo(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 搜索合作购买信息
     *
     * @param query 合作购买查询对象
     * @return
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @Operation(summary = "搜索合作购买信息")
    public RestResult<PageResult<CooperativePurchaseDO>> searchCooperativePurchase(@Validated(QueryGroup.class) CooperativePurchaseQuery query) {
        PageResult<CooperativePurchaseDO> result = cooperativePurchaseService.searchCooperativePurchase(query);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 添加合作购买信息
     *
     * @param dto 合作购买对象
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "添加合作购买信息")
    @ResponseBody
    public RestResult<Boolean> addCooperativePurchase(@RequestBody @Validated(CreateGroup.class) CooperativePurchaseDTO dto) {
        Boolean result = cooperativePurchaseService.addCooperativePurchase(dto);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改合作购买信息
     *
     * @param dto 合作购买对象
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @Operation(summary = "修改合作购买信息")
    @ResponseBody
    public RestResult<Boolean> updateCooperativePurchase(@RequestBody @Validated(UpdateGroup.class) CooperativePurchaseDTO dto) {
        Boolean result = cooperativePurchaseService.updateCooperativePurchase(dto);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除合作购买信息
     *
     * @param dto 合作购买对象
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @Operation(summary = "删除合作购买信息")
    @ResponseBody
    public RestResult<Boolean> deleteCooperativePurchase(@RequestBody @Validated(DeleteGroup.class) CooperativePurchaseDTO dto) {
        Boolean result = cooperativePurchaseService.deleteCooperativePurchase(dto);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
